import {Route, Redirect} from 'react-router-dom'
import {isLogin} from "../utiles/token";

const AuthRoute = ({component: Component, ...res}) => {
    return <Route
        {...res}  //传过来的信息（path=’/map‘）什么的
        render={props => {   //props 路由组件自带信
            const login = isLogin();
            if (login) {
                //如果登录了，将props传递过去 才能接收到路由信息
                /*console.log('props',props);
                console.log('res',res);*/
                return <Component {...props}/>
            } else {
                //如果没有登录
                return <Redirect to={{
                    pathname: '/login',
                    //跳转到登录页面，state还会携带下一个url
                    state: {
                        from: props.location
                    }
                }
                }/>
            }
        }
        }>

    </Route>
}
export  {AuthRoute}
